package com.net.tkc.pro.tool;

import com.net.tkc.pro.tool.BaiDu.OCR.HttpUtil;
//import org.json.JSONArray;
//import org.json.JSONObject;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
public class API3Tool {

        public static final String KEY = "f7b501bd859b6a8e151e449853fbc7a3";// 你的appkey
        public static final String URL = "http://v.juhe.cn/toutiao/index";
        public static final int page_size = 10;// 数量 默认10，最大40

        public static JSONArray NewGet(int page) throws Exception {
            JSONArray list = null;
            String result = null;
            String url = URL + "?key=" + KEY+"&page"+page+"&page_size"+page_size;

            try {
                result = HttpUtil.sendGet(url, "utf-8");
                JSONObject json = JSONObject.fromObject(result);
                if (json.getInt("error_code") != 0) {
                    System.out.println(json.getString("reason"));
                } else {
                    JSONObject resultarr = (JSONObject) json.opt("result");
                    list = resultarr.optJSONArray("data");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return list;
        }
}
